local extension=Package("langchaomini")
extension.extensionName="water"
local U = require "packages/utility/utility"
local T = require "packages/jbs/record/Theorem"
local pvetool=require "packages/jbs/record/PVETool"

Fk:loadTranslationTable{
    ["langchaomini"]="迷你浪潮",
    
}
local langchao__jinglinglong= General(extension, "langchao__jinglinglong","qun",4,4,General.Female)
local emo= General(extension, "langchao__emo","wei",4)
local jiqiren= General(extension, "langchao__jiqiren","shu",4)
local nijiangguai= General(extension, "langchao__nijiangguai","wu",4)
local anduyin= General(extension, "langchao__anduyin","god",4)

langchao__jinglinglong.hidden=true
emo.hidden=true
jiqiren.hidden=true
nijiangguai.hidden=true
anduyin.hidden=true

local longlang = fk.CreateTriggerSkill{
    name ="langchao__longlang",
    frequency = Skill.Compulsory,
    events = {"fk.starwave"},
    can_trigger = function(self, event, target, player, data)
  
        return player:hasSkill(self)
  
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local n= 1
      local ps= table.filter(room:getOtherPlayers(player), function(p) return p.id>0 end)
      if #ps==0 then return end
      for _, p in ipairs(ps) do
        local s=p.shield or 0
        local sv=p.maxHp or 0
        n=math.max((s+sv)//3,1)
        room:damage{
          from = player,
          to = p,
          damage = n,
          skillName = self.name,
        
        }
  
      
      end
    end,
  }

  langchao__jinglinglong:addSkill(longlang)
  langchao__jinglinglong:addSkill("wuyan")

local molang = fk.CreateTriggerSkill{
    name ="langchao__molang",
    frequency = Skill.Compulsory,
    events = {fk.Damaged},
    can_trigger = function(self, event, target, player, data)
  
        return player:hasSkill(self) and target==player and player:usedSkillTimes(self.name,Player.HistoryTurn)<2
  
    end,
    on_use = function(self, event, target, player, data)

      pvetool:trigerwave(player)

      
      
    end,
  }


  local jilang = fk.CreateTriggerSkill{
    name ="langchao__jilang",
    frequency = Skill.Compulsory,
    events = {"fk.starwave"},
    can_trigger = function(self, event, target, player, data)
  
        return player:hasSkill(self)
  
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local n=room:getBanner("@pvelv") or 1
      local ps= table.filter(room:getOtherPlayers(player), function(p) return p.id<0 end)
      if #ps==0 then return end
      for _, p in ipairs(ps) do
        room:changeShield(p,n)
        p:drawCards(2+n,self.name)
      
      end
    end,
  }


  local nilang = fk.CreateTriggerSkill{
    name ="langchao__nilang",
    frequency = Skill.Compulsory,
    events = {"fk.starwave"},
    can_trigger = function(self, event, target, player, data)
  
        return player:hasSkill(self)
  
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local ps= table.filter(room:getOtherPlayers(player,nil,true), function(p) return p.id>0 and p.shield>0 end)
      if #ps==0 then return end
      local to=table.random(ps)
      local n=to.shield//2
        room:changeShield(to,-n)
      
    end,
  }

  local shengguang= fk.CreateTriggerSkill{
    name ="langchao__shengguang",
    frequency = Skill.Compulsory,
    events = {"fk.starwave"},
    can_trigger = function(self, event, target, player, data)
  
        return player:hasSkill(self)
  
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local ps= table.filter(room:getOtherPlayers(player,nil,true), function(p) return p.id<0 and p.rest>0 end)
      if #ps==0 then return end
      local to=table.random(ps)
        room:setPlayerRest(to,0)
        room:revivePlayer(to, true, "rest")
      
    end,
  }
  
  emo:addSkill(molang)
  jiqiren:addSkill(jilang)
  jiqiren:addSkill("rende")
  nijiangguai:addSkill(nilang)
  nijiangguai:addSkill("niepan")
  anduyin:addSkill(shengguang)
Fk:loadTranslationTable{
    ["langchao__jinglinglong"] = "精灵龙",
    ["langchao__emo"] = "恶魔",
    ["langchao__nijiangguai"] = "泥浆怪",
    ["langchao__jiqiren"] = "机器人",
    ["langchao__anduyin"] = "安度因",
    ["langchao__longlang"] = "龙浪",
    ["langchao__molang"] = "魔浪",
    ["langchao__jilang"] = "机浪",
    [":langchao__jilang"] = "起浪时，使其他机器人获得1点护甲并摸2张牌",
    ["langchao__nilang"] = "泥浪",
    ["langchao__shengguang"] = "圣光",
    [":langchao__shengguang"] = "起浪时，随机唤醒一个机器人",
    [":langchao__nilang"] = "起浪时，随机移除一个玩家一半的护甲。",
    [":langchao__molang"] = "每回合限2次，受到伤害时，起浪。",
    [":langchao__longlang"] = "起浪时,对所有玩家造成等同于其（体力上限+护甲）/3的伤害。(至少一点)",
    

}

local qlong = General(extension, "langchao__qinglong","wu",5)
local longhui = fk.CreateTriggerSkill{
    name = "langchao__longhui",
    anim_type = "drawcard",
    frequency = Skill.Compulsory,
    events = {fk.EventPhaseStart,"fk.starwave"},
    can_trigger = function(self, event, target, player, data)
      if event==fk.EventPhaseStart then
        return target == player and player.phase == Player.Start and player:hasSkill(self)
      elseif event=="fk.starwave" then
        return player:hasSkill(self)

      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local n = 3
      local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick",n,"allPiles")
        if #cards > 0 then
            room:moveCards({
            ids = cards,
            to = player.id,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonJustMove,
            proposer = player.id,
            skillName = self.name,
            })
        end
    end,
}
local longlin = fk.CreateTriggerSkill{
    name = "langchao__longlin",
    mute = true,
    frequency = Skill.Compulsory,
    events = {fk.DamageInflicted},
    can_trigger = function(self, event, target, player, data)
        if event == fk.DamageInflicted then
            return target == player and  player:hasSkill(self) and data.card and data.card.type == Card.TypeTrick
        end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if event == fk.DamageInflicted then
        player:broadcastSkillInvoke(self.name)
        room:notifySkillInvoked(player,self.name,"defensive")
        return true
      end
    end,
}
qlong:addSkill(longhui)
qlong:addSkill(longlin)
Fk:loadTranslationTable{
    ["langchao__qinglong"] = "青龙",
    ["langchao__longhui"] = "龙慧",
    [":langchao__longhui"] = "锁定技，准备阶段/起浪时，你从牌堆或弃牌堆随机获得3张锦囊牌。",
    ["langchao__longlin"] = "龙鳞",
    [":langchao__longlin"] = "锁定技，防止你受到的锦囊牌伤害。",
    ["$langchao__longhui"] = "龙曜九天，慧眼如炬。",
    ["$langchao__longlin"] = "金鳞护体，风雨不侵。",
    ["~langchao__qinglong"] = "木震卦变，大凶之危。",
}
qlong.hidden=true
local zhuque = General(extension, "langchao__zhuque","shu",5,5,General.Female)
local zhuyu = fk.CreateTriggerSkill{
    name = "langchao__zhuyu",
    anim_type = "drawcard",
    frequency = Skill.Compulsory,
    events = {fk.EventPhaseStart,"fk.starwave"},
    can_trigger = function(self, event, target, player, data)
      if event==fk.EventPhaseStart then
        return target == player and player.phase == Player.Start and player:hasSkill(self)
      elseif event=="fk.starwave" then
        return player:hasSkill(self)

      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local cards = {}
      local card
      card = room:getCardsFromPileByRule(".|.|heart",1,"allPiles")
      table.insertTable(cards,card)
      card = room:getCardsFromPileByRule(".|.|diamond",1,"allPiles")
      table.insertTable(cards,card)
      card = room:getCardsFromPileByRule(".|.|club",1,"allPiles")
      table.insertTable(cards,card)
      card = room:getCardsFromPileByRule(".|.|spade",1,"allPiles")
      table.insertTable(cards,card)
        if #cards > 0 then
            room:moveCards({
            ids = cards,
            to = player.id,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonJustMove,
            proposer = player.id,
            skillName = self.name,
            })
        end
    end,
}
local tianhuo = fk.CreateActiveSkill{
    name = "langchao__tianhuo",
    anim_type = "offensive",
    min_target_num = 1,
    max_target_num = 2,
    card_num = 1,
    prompt = function(self, player)

        return "#langchao__tianhuo2"
    end,
    can_use = function(self, player)
      return  true
    end,
    card_filter = function(self, to_select, selected)
        return #selected == 0 and not table.contains(type(Self:getMark("@langchao__tianhuo-phase")) == "table" and Self:getMark("@langchao__tianhuo-phase") or {},Fk:getCardById(to_select):getSuitString(true))
    end,
    target_filter = function(self, to_select, selected)
      local target = Fk:currentRoom():getPlayerById(to_select)
        return #selected < 2 and to_select ~= Self.id and ((Self.role == "rebel" and target and target.role ~= "rebel") or ((Self.role == "lord" or Self.role == "loyalist") and (target and target.role ~= "lord" and target.role ~= "loyalist")))
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      local card = Fk:getCardById(effect.cards[1])
      local suit = card:getSuitString(true)
      local record = type(player:getMark("@langchao__tianhuo-phase")) == "table" and player:getMark("@langchao__tianhuo-phase") or {}
      table.insertIfNeed(record, suit)
      room:setPlayerMark(player, "@langchao__tianhuo-phase", record)
      room:moveCardTo(card,Card.DiscardPile,player,fk.ReasonDiscard)
      for _, pid in ipairs(effect.tos) do
        local to = room:getPlayerById(pid)
          room:damage({
            from = player,
            to = to,
            damage = 1,
            damageType = fk.FireDamage,
            skillName = self.name,
          })
      end
    end,
}
zhuque:addSkill(zhuyu)
zhuque:addSkill(tianhuo)
Fk:loadTranslationTable{
    ["langchao__zhuque"] = "朱雀",
    ["langchao__zhuyu"] = "朱羽",
    [":langchao__zhuyu"] = "锁定技，准备阶段/起浪时，你从牌堆或弃牌堆随机获得四个种花色各一张牌。",
    ["langchao__tianhuo"] = "天火",
    [":langchao__tianhuo"] = "出牌阶段每种花色限一次，你可以弃置一张牌然后对至多两名敌方角色各造成一点火焰伤害。",

    ["#langchao__tianhuo1"] = "你可以弃置一张牌并对至多两名敌方角色各造成一点火焰伤害。",
    ["#langchao__tianhuo2"] = "每种花色限一次，你可以弃置一张牌并对至多两名敌方角色各造成一点火焰伤害。",
    ["@langchao__tianhuo-phase"] = "天火",
    ["$langchao__zhuyu"] = "玄羽厉火，赤鳞硕天。",
    ["$langchao__tianhuo"] = "离火天降，炼狱即临。",
    ["~langchao__zhuque"] = "火离卦变，大凶之危。",
}
zhuque.hidden=true

local baihu = General(extension, "langchao__baihu","qun",5)
baihu.hidden=true
local huwei = fk.CreateTriggerSkill{
    name = "langchao__huwei",
    anim_type = "drawcard",
    frequency = Skill.Compulsory,
    events = {fk.EventPhaseStart,"fk.starwave"},
    can_trigger = function(self, event, target, player, data)
      if event==fk.EventPhaseStart then
        return target == player and player.phase == Player.Start and player:hasSkill(self)
      elseif event=="fk.starwave" then
        return player:hasSkill(self)

      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local n = 3
      local cards = room:getCardsFromPileByRule("slash",n,"allPiles")
        if #cards > 0 then
            room:moveCards({
            ids = cards,
            to = player.id,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonJustMove,
            proposer = player.id,
            skillName = self.name,
            })
        end
    end,
}
local tianxiao = fk.CreateTriggerSkill{
    name = "langchao__tianxiao",
    anim_type = "offensive",
    frequency = Skill.Compulsory,
    events = {fk.AfterCardTargetDeclared},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self) and
        data.card.trueName == "slash" and
        #player.room:getUseExtraTargets( data, true) > 0
    end,
    on_use = function(self, event, target, player, data)
      for _, id in ipairs(player.room:getUseExtraTargets( data, true)) do
        local p = player.room:getPlayerById(id)
        if  ((player.role == "rebel" and p.role ~= "rebel") or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist"))) then
          player.room:doIndicate(player.id, {id})
          TargetGroup:pushTargets(data.tos, id)
        end
      end
    end,
}
local tianxiao_targetmod = fk.CreateTargetModSkill{
    name = "#langchao__tianxiao_targetmod",
    frequency = Skill.Compulsory,
    bypass_distances = function(self, player, skill, card, to)
      return player:hasSkill(self) and card and card.trueName == "slash"
    end,
    residue_func = function(self, player, skill, scope)
        if skill.trueName == "slash_skill" and player:hasSkill(self) then
           
            return 2
            
        end
        return 0
      end,
}
tianxiao:addRelatedSkill(tianxiao_targetmod)
baihu:addSkill(huwei)
baihu:addSkill(tianxiao)
Fk:loadTranslationTable{
    ["langchao__baihu"] = "白虎",
    ["langchao__huwei"] = "虎威",
    [":langchao__huwei"] = "锁定技，准备阶段/起浪时，你从牌堆或弃牌堆随机获得3张【杀】。",
    ["langchao__tianxiao"] = "天啸",
    [":langchao__tianxiao"] = "锁定技，你使用【杀】无距离限制且指定所有敌方角色为目标，出牌阶段你可以多使用两张【杀】。",

    ["$langchao__huwei"] = "..凶意来潮。",
    ["$langchao__tianxiao"] = "白茫越四野，虎啸震八方。",
    ["~langchao__baihu"] = "金兑卦变，大凶之危。",
}

local xuanwu = General(extension, "langchao__xuanwu","wei",5)
local shengqu = fk.CreateTriggerSkill{
    name = "langchao__shengqu",
    mute = true,
    frequency = Skill.Compulsory,
    events = {fk.DamageInflicted,fk.Damaged},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) then
            local room = player.room
            if event == fk.DamageInflicted and data.damage and data.damage > 1 then 
              local n = 0
                for _, p in ipairs(room:getOtherPlayers(player)) do
                    if ((player.role == "rebel" and p.role == "rebel") or ((player.role == "lord" or player.role == "loyalist") and (p.role == "lord" or p.role == "loyalist"))) then
                    n = n + 1
                    if n > 1 then
                          return true
                        end
                    end

                end
            elseif event == fk.Damaged then
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if event == fk.DamageInflicted  then
        player:broadcastSkillInvoke(self.name)
        room:notifySkillInvoked(player,self.name,"defensive")
        data.damage=data.damage-1
      elseif event == fk.Damaged then
        if not player.dead then
            player:broadcastSkillInvoke(self.name)
            room:notifySkillInvoked(player,self.name,"drawcard")
            player:drawCards(2,self.name)
        end
      end
    end,
}
local xuankai = fk.CreateTriggerSkill{
    name = "langchao__xuankai",
    mute = true,
    priority = 2,
    frequency = Skill.Compulsory,
    events = {fk.Damaged,fk.CardUsing,fk.Damage},
    can_trigger = function(self, event, target, player, data)
        if event == fk.Damaged then
            return target == player and player:hasSkill(self) and player:getMark("@@langchao__xuankai") == 0
        elseif event == fk.CardUsing then
            return target == player and player:hasSkill(self) and player:getMark("@@langchao__xuankai") > 0
        elseif event == fk.Damage then
            return target == player and player:hasSkill(self)
        end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if event == fk.Damaged then
        room:setPlayerMark(player,"@@langchao__xuankai",1)
      elseif event == fk.CardUsing then
        player:broadcastSkillInvoke(self.name)
        room:notifySkillInvoked(player,self.name,"offensive")
        room:setPlayerMark(player,"@@langchao__xuankai",0)
        data.disresponsiveList = data.disresponsiveList or {}
        for _, p in ipairs(room.alive_players) do
          table.insertIfNeed(data.disresponsiveList, p.id)
        end
      elseif event == fk.Damage then
  
            if not player.dead then
                player:broadcastSkillInvoke(self.name)
                room:notifySkillInvoked(player,self.name,"drawcard")
                player:drawCards(2,self.name)
            end
      
      end
    end,
}
xuanwu:addSkill(shengqu)
xuanwu:addSkill(xuankai)
xuanwu.hidden=true
Fk:loadTranslationTable{
    ["langchao__xuanwu"] = "玄武",
    ["langchao__shengqu"] = "圣躯",
    [":langchao__shengqu"] = "锁定技，当你受到伤害后，你摸两张牌；若友方角色（不含自身）大于1，受到伤害-1。",
    ["langchao__xuankai"] = "玄铠",
    [":langchao__xuankai"] = "锁定技，你受到伤害后，你使用的下一次张牌无法被响应；你造成伤害后，你摸两张牌。",

    ["@@langchao__xuankai"] = "玄铠",

    ["$langchao__shengqu"] = "神龟天泽，其寿永昌。",
    ["$langchao__xuankai"] = "玄踞北冥，不动如山。",
    ["~langchao__xuanwu"] = "水坎卦变，大凶之危。",
}


local huofu= General(extension, "langchao__huofu","wu",2)
local fengbaogoutouren= General(extension, "langchao__fengbaogoutouren","qun",4)

huofu.hidden=true
fengbaogoutouren.hidden=true
local chongfeng = fk.CreateTriggerSkill{
    name = "langchao__chongfeng",
    frequency = Skill.Compulsory,
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
      if event==fk.EventPhaseStart then
        return target == player and player.phase == Player.Start and player:hasSkill(self)

      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local ps= table.filter(room:getOtherPlayers(player), function(p) return p.id>0 end)
      if #ps==0 then return end
      local p=table.random(ps)
        room:damage{
          from = player,
          to = p,
          damage = 4,
          skillName = self.name,
        
        }
  
      
    end,
}


local yishi = fk.CreateTriggerSkill{
  name = "langchao__yishi",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if event==fk.EventPhaseStart then
      return target == player and player.phase == Player.Start and player:hasSkill(self)

    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ps= table.find(room:getOtherPlayers(player), function(p) return p.general=="langchao__aolajier" end)
    if not ps then 
      local pps= table.filter(room:getOtherPlayers(player), function(p) return p.id<0 end)
      if #pps==0 then return end
      local p=table.random(pps)
      room:changeHero(p,"langchao__aolajier", true, false, false, false)
    else
      pvetool:trigerwave(player)
    end
    
  end,
}
huofu:addSkill(chongfeng)
fengbaogoutouren:addSkill(yishi)

Fk:loadTranslationTable{
  ["langchao__huofu"] = "霍弗",
  ["langchao__fengbaogoutouren"]="风暴狗头人",
  ["langchao__chongfeng"]="冲锋",
  ["langchao__yishi"]="仪式",
  [":langchao__yishi"]="准备阶段，若场上没有风领主奥拉基尔则召唤之；否则，起浪。",
  [":langchao__chongfeng"]="准备阶段，对一名玩家造成4点伤害",

}

return extension